import store from '@/store'

export default {
    searchList(list, keyWord) {
        var arr = [];
        for (var i = 0; i < list.length; i++) {
            if (list[i].productName.indexOf(keyWord) >= 0) {
                arr.push(list[i]);
            }
        }
        return arr;
    },
    // 判断数组值是否重复
    isRepeat(arr) {
        var hash = {}
        for (var i in arr) {
            if (hash[arr[i]]) { return true }
            hash[arr[i]] = true
        }
        return false
    },
    // 码规则
    codeRule(e) {
        // console.log(e)
        let index = e.indexOf('code')
        if(index > -1){
            let a = e.split("=")
            let b = a[a.length - 1]
            return b
        }else{
            // let c = e.split(")")
            // let d = c[c.length - 1]
            let d = e.slice(-20)
            return d
        }
    },
    // 采购入库扫码规则
    codeBoxRule(e) {
        let str = e.replace(/\s+/g, "") // 过滤空格
        str = str.replace(/\（/g,"(").replace(/\）/g,")") // 中文括号转换为英文括号
        // console.log(str)
        let code = ''
        let productionDate = ''
        let expirationDate = ''
        if(str.indexOf('(17)') > -1){
            let a = str.split('(17)')
            code = str.slice(-20)
            productionDate = a[a.length - 2].slice(-6)
            expirationDate = a[a.length - 1].slice(0,6)
        }else{
            code = str.slice(-20)
            let index = str.indexOf('code')
            if(index > -1){
                // console.log(store.state.user.users.dept.deptName)
                productionDate = store.state.user.users.dept.deptName
                expirationDate = store.state.user.users.dept.deptName
            }else{
                productionDate = str.slice(-36,-30)
                expirationDate = str.slice(-28,-22)
            }
        }
        // let code = e.slice(-20)
        // let a = e.split('(17)')
        // let productionDate = a[a.length - 2].slice(-6)
        // let expirationDate = a[a.length - 1].slice(0,6)
        return { code, productionDate, expirationDate }
    },
}